import getdata from '@/common/ajax.js';
function uploding (success){
		var _this = this
		uni.chooseImage({
			count: 1, //默认9
			// sourceType: ['album'], //从相册选择
			success: function (res) {
			uni.uploadFile({
			    url: getdata.websiteUrl+'/storage/upload', //仅为示例，非真实的接口地址
			    filePath: res.tempFilePaths[0],
			    name: 'file',
			    formData: {
			        'user': 'test'
			    },
			    success: (uploadFileRes) => {
					console.log(111,uploadFileRes)
					console.log(111,JSON.parse(uploadFileRes.data).data.url)
					 uni.request({
					 	url:  JSON.parse(uploadFileRes.data).data.url,
					 	method: 'GET',
					 	responseType: 'arraybuffer',
					 	success: ress => {
							console.log(111)
					 		let base64 = wx.arrayBufferToBase64(ress.data); //把arraybuffer转成base64
					 		base64 = 'data:image/jpeg;base64,' + base64; //不加上这串字符，在页面无法显示的哦
					 		success(base64);
							console.log(success,base64,1121212)
					 	}
					 });
					
			    }
			});
			}
		});
	};
	function tips(SuserInfo){ //提示去认证
	console.log(SuserInfo,'SuserInfo')
		if(SuserInfo){
			uni.showModal({
			    title: '提示',
			    content: '你还未认证，请前去认证',
			    success: function (res) {
			        if (res.confirm) {
							uni.navigateTo({
								url:'/pages/mine/authentication/authentication'
							})
			        } else if (res.cancel) {
			            console.log('用户点击取消');
			        }
			    }
			});
		}else{
			uni.showModal({
			    title: '提示',
			    content: '你还未认证，请前去认证',
			    success: function (res) {
			        if (res.confirm) {
							uni.navigateTo({
								url:'/pages/mine/identity/identity'
							})
			        } else if (res.cancel) {
			            console.log('用户点击取消');
			        }
			    }
			});
		}
	};
	function diction(msg){ //权限 不是商家，无法打开
		uni.showModal({
		    title: '提示',
		    content: msg,
			showCancel:false,
		    success: function (res) {
		    }
		});
	};
	export default {
		uploding: function (success) {
			return uploding(success)
		},
		tips: function (e) {
			return tips(e)
		},diction: function (msg) {
			return diction(msg)
		},
	};